package ace.module.upms.sdk.core.feign.impl;

import ace.cmp.core.model.R;
import ace.cmp.openfeign.security.oauth2.core.config.FeignInternalServerOauth2SecurityConfig;
import ace.module.common.api.annotation.ApiRemoteProxyPriority;
import ace.module.common.api.model.input.AppIdListInput;
import ace.module.upms.api.model.dto.UpmsOrganizationDto;
import ace.module.upms.api.model.input.UpmsOrgBindAccountInput;
import ace.module.upms.sdk.core.constant.SdkConstant;
import ace.module.upms.sdk.core.feign.UpmsOrganizationFeignApi;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 组织 rpc feign.
 *
 * @author Caspar
 */
@FeignClient(
    name = "${spring.cloud.openfeign.client.config.upmsOrganizationFeign.name:" + SdkConstant.FEIGN_SERVICE_NAME + "}",
    contextId = "upmsOrganizationFeign",
    path = UpmsOrganizationFeign.PATH,
    configuration = FeignInternalServerOauth2SecurityConfig.class,
    primary = false
)
@ApiRemoteProxyPriority
public interface UpmsOrganizationFeign extends UpmsOrganizationFeignApi {

  String PATH = "${spring.cloud.openfeign.client.config.upmsOrganizationFeign.path:/upms/upms-organization/rpc}";

  @Operation(summary = "查询账户关联的组织", description = "key=accountId value=数据")
  @GetMapping("/getAccountIdAndOrgMapByUpmsAppIdAndIamAccountIdIn")
  R<Map<Long, List<UpmsOrganizationDto>>> getAccountIdAndOrgMapByUpmsAppIdAndIamAccountIdIn(
      @RequestParam("upmsAppId") Long upmsAppId,
      @RequestParam("iamAccountIds") List<Long> iamAccountIds);

  @Operation(summary = "查询账户关联的组织", description = "")
  @GetMapping("/getByUpmsApIdAndIamAccountId")
  R<List<UpmsOrganizationDto>> getByUpmsApIdAndIamAccountId(@RequestParam("upmsAppId") Long upmsAppId, @RequestParam("iamAccountId") Long iamAccountId);

  @Operation(summary = "保存组织与账户绑定关系,以当前数据为准,含新增、修改、删除操作.", description = "")
  @PostMapping("/saveOrgAccountRelation")
  R<Void> saveOrgAccountRelation(@RequestBody AppIdListInput<UpmsOrgBindAccountInput> inputs);
}